package com.gs.djys.checkfragments.sign;

import android.app.Activity;
import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.gs.djys.Base.AddBean;
import com.gs.djys.Base.MyAppliCation;
import com.gs.djys.Base.Urls;
import com.gs.djys.callback.StringDialogCallback;
import com.gs.djys.checkfragments.inquest.InquestBean;
import com.gs.djys.mvp.BasePresenterImpl;
import com.gs.djys.signs.SignsBean;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class SignPresenter extends BasePresenterImpl<SignContract.View> implements SignContract.Presenter{
    @Override
    public void getData(String req_no) {
        OkGo.<String>get(Urls.SERVER + "/road/lictran/licApp/request/loadXcky")
                .params("req_no", req_no)
                .params("user_code", MyAppliCation.spUtils.getString("userCode"))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        SignsBean inquestBean = JSON.parseObject(response.body(),SignsBean.class);
                        if (mView == null)
                            return;
                        if (inquestBean.getCode().equals("0000")){
                            mView.getDatas(inquestBean);
                        }else {
                            mView.onRequestError(inquestBean.getMessage());
                        }
                    }
                });
    }
    @Override
    public void addData(String isty, String json, Activity activity) {
        OkGo.<String>post(Urls.SERVER + "/road/lictran/licApp/request/saveOrUpdateQrqz")
                .params("user_code", MyAppliCation.spUtils.getString("userCode"))
                .params("opt_code", isty)
                .params("data", json)
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        AddBean addBean = JSON.parseObject(response.body(),AddBean.class);
                        if (mView == null)
                            return;
                        if (addBean.getCode().equals("0000")){
                            mView.addDatas(addBean);
                        }else {
                            mView.onRequestError(addBean.getMessage());
                        }
                    }
                });
    }
}
